﻿@{
    var defaultGridPageSize = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().DefaultGridPageSize;
    var gridPageSizes = EngineContext.Current.Resolve<Nop.Core.Domain.Common.AdminAreaSettings>().GridPageSizes;

    //page title
    ViewBag.Title = T("Admin.ContentManagement.Blog.Comments").Text;
}
@{
    int? filterByBlogPostId = ViewBag.FilterByBlogPostId;
}
<div class="section-header">
    <div class="title">
        <img src="@Url.Content("~/Administration/Content/images/ico-content.png")" alt="" />
        @T("Admin.ContentManagement.Blog.Comments")
    </div>
    <div class="options">
    </div>
</div>
<table class="adminContent">
    <tr>
        <td>
            <div id="comments-grid"></div>
            @{
                string readUrl = "";
                if (filterByBlogPostId.HasValue)
                {
                    readUrl = Url.Action("Comments", "Blog", new {filterByBlogPostId = filterByBlogPostId.Value});
                }
                else
                {
                    readUrl = Url.Action("Comments", "Blog");
                }
            }
            <script>
                $(document).ready(function () {
                    $("#comments-grid").kendoGrid({
                        dataSource: {
                            type: "json",
                            transport: {
                                read: {
                                    url: "@readUrl",
                                    type: "POST",
                                    dataType: "json"
                                },
                                destroy: {
                                    url: "@Html.Raw(Url.Action("CommentDelete", "Blog"))",
                                    type: "POST",
                                    dataType: "json"
                                }
                            },
                            schema: {
                                data: "Data",
                                total: "Total",
                                errors: "Errors",
                                model: {
                                    id: "Id",
                                    fields: {
                                        //do not implicitly specify all fields
                                        //we do it only for fields which implicitly require it
                                        //otherwise, they'll be formatted wrong way
                                        CreatedOn: {type: "date" }
                                    }
                                }
                            },
                            error: function(e) {
                                display_kendoui_grid_error(e);
                                // Cancel the changes
                                this.cancelChanges();
                            },
                            pageSize: @(defaultGridPageSize),
                            serverPaging: true,
                            serverFiltering: true,
                            serverSorting: true
                        },
                        pageable: {
                            refresh: true,
                            pageSizes: [@(gridPageSizes)]
                        },
                        editable: {
                            confirmation: false,
                            mode: "inline"
                        },
                        scrollable: false,
                        columns: [{
                            field: "Id",
                            title: "ID",
                            width: 50
                        }, {
                            field: "BlogPostTitle",
                            title: "@T("Admin.ContentManagement.Blog.Comments.Fields.BlogPost")",
                            width: 200,
                            template: '<a href="@Url.Content("~/Admin/Blog/Edit/")#=BlogPostId#">#:BlogPostTitle#</a>'
                        }, {
                            field: "CustomerId",
                            title: "@T("Admin.ContentManagement.Blog.Comments.Fields.Customer")",
                            width: 200,
                            template: '<a href="@Url.Content("~/Admin/Customer/Edit/")#=CustomerId#">#:CustomerInfo#</a>'
                        }, {
                            field: "Comment",
                            title: "@T("Admin.ContentManagement.Blog.Comments.Fields.Comment")",
                            encoded: false
                        }, {
                            field: "CreatedOn",
                            title: "@T("Admin.ContentManagement.Blog.Comments.Fields.CreatedOn")",
                            width: 200,
                            type: "date",
                            format: "{0:G}"
                        }, {
                            command: { name: "destroy", text: "@T("Admin.Common.Delete")" },
                            title: "@T("Admin.Common.Delete")",
                            width: 100
                        }]
                    });
                });
            </script>
        </td>
    </tr>
</table>